package org.csu.petserver.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.csu.petserver.domain.User;
import org.csu.petserver.persistence.UserMapper;
import org.csu.petserver.service.AdminLogin;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("AdminLogin")
@MapperScan("org.csu.petserver.persistence")
public class AdminLoginImpl implements AdminLogin {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserById(String id) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    public User getUserByIdAndPassword(String id,String password){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id).eq("password",password);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }
    @Override
    public boolean checkPassword(User user, String password) {
        if(user.getPassword().equals(password)){
            return true;
        }
        return false;
    }

    @Override
    public boolean updatePassword(User user, String password) {
        user.setPassword(password);
        userMapper.updateById(user);
        return true;
    }
}
